package com.glory.brepda.activity;

import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.glory.brepda.R;
import com.glory.brepda.base.BaseActivity;
import com.glory.brepda.utils.SearchPopupWindow;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;
import com.zhihu.matisse.Matisse;
import com.zhihu.matisse.MimeType;
import com.zhihu.matisse.engine.impl.GlideEngine;

import java.util.Arrays;
import java.util.List;

import butterknife.BindView;

public class ScanTestEditTextActivity extends BaseActivity {

    @BindView(R.id.llMain)
    LinearLayout llMain;
    @BindView(R.id.scan_text)
    FreeUI_ClearEditText scan_text;
    @BindView(R.id.scan)
    ImageView scan;

    @BindView(R.id.flCheckItem)
    FrameLayout flCheckItem;
    @BindView(R.id.tvCheckItem)
    TextView tvCheckItem;
    @BindView(R.id.ivCheckItem)
    ImageView ivCheckItem;
    @BindView(R.id.button)
    Button button;

    private final List<String> itemList = Arrays.asList(
            "Apple", "Banana", "Cherry", "Date", "Fig", "Grape", "Lemon", "Mango", "Orange", "Peach", "Pineapple"
    );

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_scan_test_edit_text;
    }

    @Override
    protected void initView() {
        setMainLayout(llMain);
    }

    @Override
    protected void initData() {

        scan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startQrScanner(0xf1);
            }
        });

        flCheckItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                new SearchPopupWindow(ScanTestEditTextActivity.this, itemList, tvCheckItem,flCheckItem, selected -> tvCheckItem.setText(selected));
            }
        });

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Matisse.from(ScanTestEditTextActivity.this)
                        .choose(MimeType.of(MimeType.JPEG, MimeType.PNG))
                        .countable(true) // 是否显示选择顺序
//                        .maxSelectable(99) // 最多选择5张
                        .imageEngine(new GlideEngine()) // 自定义图片加载方式（需要实现）
                        .forResult(1001);

            }
        });
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == RESULT_OK && requestCode == 1001) {
//            String qrResult = data.getStringExtra("SCAN_RESULT"); // 获取扫码结果
//            if (qrResult != null) {
//                if (requestCode == 0xf1) {
//                    scan_text.setText(qrResult);
//                }
//            }
            List<Uri> result = Matisse.obtainResult(data);
            showToast(""+result.size(),true);
        }
    }



//        IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
//        if (result != null && result.getContents() != null) {
//            scan_text.setText(result.getContents());
//        }



}